import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core';
import {CommentModel} from "../../model/comment.model";
import {COMMENT} from "../../service/comment.service";
import {LocalStorage} from "../../app.local-storage";
import {WfToast} from "../../utils/toast.utils";

@Component({
  selector: 'app-rating-modal-view',
  templateUrl: './rating-modal-view.component.html',
  styleUrls: ['./rating-modal-view.component.scss']
})
export class RatingModalViewComponent implements OnInit {
  @Input('showModal') public isModalShown: boolean = false;
  @Output('modalClose') public modalClose = new EventEmitter();
  comment:CommentModel;

  constructor(private COMMENT:COMMENT,private WFTOAST:WfToast,private ls:LocalStorage) {
  }

  ngOnInit() {
    this.comment = new CommentModel(this.ls.get('commentNo'))
  }
  commentScore(array, score, index) {
    for (let i = 0; i < this.comment[array].length; i++) {
      if (i > index) {
        this.comment[array][i] = false
      } else {
        this.comment[array][i] = true
      }
    }
    this.comment[score] = index + 1
    console.log(this.comment)
  }
  commentFunc(){
    this.COMMENT.comment(this.comment.genRequestData(),v=>{
      this.WFTOAST.msg("评价成功")
      this.onHidden();
    })
  }

  public showModal(): void {
    this.isModalShown = true;
  }

  public onHidden(): void {
    this.isModalShown = false;
  }

}
